-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ngen_cal_model_configure
model hook
#161
feat: ngen_cal_model_configure
model hook
#161
Conversation
ngen_cal_model_configure
model hook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change in behavior of the Agent and its interaction with the model config is quite likely to break.
|
||
if self._job is None: | ||
self._job = JobMeta(model_conf['type'], workdir, log=log) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These steps are minutely important to the use of the Agent, and I don't think they can be dropped...The agent manipulates the configs to ensure root/workdirs are set appropriately under the automatically created agent working dirs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think they are dropped? I was just pulling them from the pydantic
model instance now instead of the dictionary. Probably missing something thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this comment ended up being unclear, it was intended for lines 81-83 where workdir and binary are configured relative to the Agent's dynamically created workdir. These are critical for correct operation of agents especially in PSO where multiple agents are running simultaneously.
As noted in disscussion with @aaraney the current resolved_binary
isn't actually working as intended, and is its own bug which can be resolved in this context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #167 to track this.
d6e4ca1
to
1f9770f
Compare
resolved_binary = Path(model_conf['binary']).resolve() | ||
model_conf['workdir'] = self.job.workdir | ||
self._model = Model(model=model_conf, binary=resolved_binary) | ||
self._job = JobMeta(ngen_model.type, workdir, log=log) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are still missing the updated model workdir. An agent has a job which nests information and job/model files under a dynamically created workdir job.workdir
. Any model instance associated with that job
must have its workdir
aligned with the job.workdir
, so we need to update the model reference like such
self._job = JobMeta(ngen_model.type, workdir, log=log) | |
self._job = JobMeta(ngen_model.type, workdir, log=log) | |
ngen_model.workdir = self.job.workdir |
plugins = cast(List[Union[Callable, ModuleType]], general.plugins) | ||
plugin_manager = setup_plugin_manager(plugins) | ||
|
||
print(_loaded_plugins(plugin_manager)) | ||
|
||
# setup plugins | ||
plugin_manager.hook.ngen_cal_configure(config=general) | ||
model_inner._plugin_manager.hook.ngen_cal_model_configure(config=model_inner) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An agent effectively side effects the Model
it associates with, particularly setting the workdir
for that model run. Because of this, we probably need to initialize the Agent before passing the Model to anything else, including plugins.
model_inner._plugin_manager.hook.ngen_cal_model_configure(config=model_inner) | |
# Initialize the starting agent | |
# WARNING: Agent sets the model workdir, so initialize it before using the model object for anything that may require an accurate workdir | |
agent = Agent(model, general.workdir, general.log, general.restart, general.strategy.parameters) | |
model_inner._plugin_manager.hook.ngen_cal_model_configure(config=model_inner) |
|
||
# Initialize the starting agent | ||
agent = Agent(model, general.workdir, general.log, general.restart, general.strategy.parameters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Initialize the starting agent | |
agent = Agent(model, general.workdir, general.log, general.restart, general.strategy.parameters) |
db0819f
to
6a3ca77
Compare
6a3ca77
to
dd18e0e
Compare
Agent mutates the model config; If ngen_cal_model_configure is called before the Agent is initialized, it won't get the final view of the config before calibration. Co-authored-by: Nels <[email protected]>
Co-authored-by: Nels <[email protected]>
Add model hook:
ngen_cal_model_configure
hook that mirrors the existingngen_cal_configure
hook.Additions
ngen_cal_model_configure
model hook; Called before calibration begins. This allow plugins to perform initial configuration.unwrap
method added tongen.cal.ngen.Ngen
. Returns the instance's__root__
attribute.Changes
Agent
now takes aModel
instance as a parameter. Previously, the raw config was passed.